package com.jisf.driver.auth;

import com.jisf.driver.response.Result;
import com.jisf.driver.response.ResultCode;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * @Classname MyExpiredSessionStrategy
 * @Description TODO 用户被挤下线时的处理
 * @Date 2022/4/4 23:26
 * @Created by jisf：【429627912@qq.com】
 */
@Component
public class MyExpiredSessionStrategy extends JsonAuthentication implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        Result result = Result.error(ResultCode.USER_ACCOUNT_USE_BY_OTHERS);
        this.WriteJSON(event.getRequest(), event.getResponse(), result);
    }
}
